package com.gxa.xly2024.service.impl;

import com.gxa.xly2024.mapper.AdminMapper;
import com.gxa.xly2024.pojo.Admin;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@Service
public class AdminServiceImpl {
    @Resource
    private AdminMapper adminMapper;

    public Map<String, Object> selectLogin(String user_name, String user_pwd) {
        Admin admin = this.adminMapper.selectLogin(user_name, user_pwd);
        Map<String, Object> map = new HashMap<>();
        System.out.println(admin);
        if (admin == null) {
            // 如果 login 为 null，则表示查询未找到匹配的记录
            map.put("code", 404); // 假设使用 404 表示未找到
            map.put("msg", "未找到匹配的登录信息");
            map.put("data", null);
        } else {
            // 如果 login 不为 null，则表示查询找到了匹配的记录
            map.put("code", 200);
            map.put("msg", "查询信息成功");
            map.put("data", admin);
        }

        return map;
    }
    public Map<String, Object> insertsign(String user_name, String user_pwd) {
        System.out.println(user_name+' '+user_pwd);
        this.adminMapper.insertsign(user_name, user_pwd);
        System.out.println(user_name+' '+user_pwd);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "新增用户成功");
        map.put("data", null);

        return map;
    }

    public Map<String, Object> selectId(Integer id) {
        Admin admin =this.adminMapper.selectId(id);

        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "查询信息成功");
        map.put("data", admin);
        return map;

    }
}